package cn.com.web.Servlet;

import cn.com.domain.Order;
import cn.com.service.OrderService;
import cn.com.service.impl.OrderServiceImpl;
import cn.com.utils.Dateutils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/AlterOrderServlet")
public class AlterOrderServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //获取订单id，顾客名字，预定房间，入住时间和退房时间和是否退房的参数
        String order_start = request.getParameter("order_start");
        String order_end = request.getParameter("order_end");
        String order_id = request.getParameter("order_id");
        String order_room_name = request.getParameter("order_room_name");
        String order_customer_name = request.getParameter("order_customer_name");
        String ischeck = request.getParameter("ischeck");
        int order_days = Dateutils.calculateDaysDifference(order_start,order_end);

        //定义OrderService对象
        OrderService service=new OrderServiceImpl();
        //获取订单价格
        double order_price = service.findpriceByName(order_room_name) * order_days;
        //封装为对象
        Order order=new Order(0,order_room_name,order_customer_name,
                order_days,order_price,order_start,order_end,ischeck);
        //调用修改方法
        service.alterOrderbyid(order,order_id);
        //转到查询订单页面
        request.getRequestDispatcher("FindOrderByPageServlet?currentPage=1&rows=5")
                .forward(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }
}
